#include "mytest.h"
#include "ui_mytest.h"

#include <QThread>
#include <QDebug>
#include "mythread.h"

MyTest::MyTest(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MyTest)
{
    ui->setupUi(this);
    qDebug() << QThread::currentThreadId();

    QThread* t1 = new QThread();
    Task1* task1 = new Task1();
    task1->moveToThread(t1);

    QThread* t2 = new QThread();
    Task2* task2 = new Task2();
    task2->moveToThread(t2);

    QThread* t3 = new QThread();
    Task3* task3 = new Task3();
    task3->moveToThread(t3);

    connect(this, &MyTest::sendNum, task1, &Task1::working);
    connect(ui->start, &QPushButton::clicked, [=](){

        emit sendNum(1000);
        t1->start();
    });

    connect(task1, &Task1::sendArray, task2, &Task2::working);
    connect(task1, &Task1::sendArray, task3, &Task3::working);
    connect(task1, &Task1::sendArray, [=](QVector<int> v){
        t2->start();
        t3->start();

        for(int i = 0; i < v.size(); i++)
        {
            ui->randomList->addItem(QString().number(v[i]));
        }
    });

    connect(task2, &Task2::sendArray, [=](QVector<int> v){

        for(int i = 0; i < v.size(); i++)
        {
            ui->bubbleList->addItem(QString().number(v[i]));
        }
    });

    connect(task2, &Task2::sendArray, [=](QVector<int> v){

        for(int i = 0; i < v.size(); i++)
        {
            ui->quickList->addItem(QString().number(v[i]));
        }
    });
}


MyTest::~MyTest()
{
    delete ui;
}

